home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
comm
/
term
/
term34Source.lha
/
ClipPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
10KB
|
382 lines
/*
** ClipPanel.c
**
** Editing panel for clipboard configuration
**
** Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
enum { GAD_UNIT,GAD_CHARDELAY,GAD_LINEDELAY,GAD_PROMPT,GAD_SENDTIMEOUT,GAD_PACING,GAD_PREFIX,GAD_SUFFIX,
GAD_USE,GAD_CANCEL,GAD_DEFAULT };
STATIC STRPTR PacingMode[7];
STATIC STRPTR __saveds
ShowTime(struct Gadget *SomeGadget,WORD Level)
{
return(LocaleSeconds(Level));
}
STATIC struct Gadget *
CreateAllGadgets(struct Configuration *Config,struct Gadget **GadgetArray,struct Gadget **GadgetList,BYTE *Default)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD Counter = 0;
LocalizeString(PacingMode,MSG_CLIPPANEL_DIRECT_TXT,MSG_CLIPPANEL_KEYDELAY_TXT);
SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
memset(&NewGadget,0,sizeof(struct NewGadget));
if(Gadget = CreateContext(GadgetList))
{
LONG Width;
SZ_AddLeftOffset(SZ_LeftOffsetDelta(MSG_CLIPPANEL_UNIT_GAD,MSG_CLIPPANEL_TEXT_PACING_GAD));
SZ_ResetMaxWidth();
SZ_UpdateMaxWidth(CYCLE_KIND,NULL,0,PacingMode);
SZ_UpdateMaxWidth(INTEGER_KIND,NULL,20,NULL);
Width = SZ_ResetMaxWidth();
if(Width < 108)
Width = 108;
SZ_SetWidth(Width);
NewGadget . ng_GadgetText = LocaleString(MSG_CLIPPANEL_UNIT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTIN_MaxChars, 3,
GTIN_Number, Config -> ClipConfig -> ClipboardUnit,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_CLIPPANEL_CHAR_DELAY_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignExtra, TRUE,
GTSL_Min, 0,
GTSL_Max, 10 * 100,
GTSL_Level, Config -> ClipConfig -> CharDelay,
GTSL_MaxLevelLen, 7,
GTSL_LevelFormat, "%s s",
GTSL_DispFunc, ShowTime,
PGA_Freedom, LORIENT_HORIZ,
GA_Immediate, TRUE,
GA_RelVerify, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_CLIPPANEL_LINE_DELAY_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTSL_Min, 0,
GTSL_Max, 10 * 100,
GTSL_Level, Config -> ClipConfig -> LineDelay,
GTSL_MaxLevelLen, 7,
GTSL_LevelFormat, "%s s",
GTSL_DispFunc, ShowTime,
PGA_Freedom, LORIENT_HORIZ,
GA_Immediate, TRUE,
GA_RelVerify, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_CLIPPANEL_LINE_PROMPT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTST_MaxChars, 255,
GTST_String, Config -> ClipConfig -> LinePrompt,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_CLIPPANEL_SEND_TIMEOUT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTSL_Min, 0,
GTSL_Max, 10 * 100,
GTSL_Level, Config -> ClipConfig -> SendTimeout,
GTSL_MaxLevelLen, 7,
GTSL_LevelFormat, "%s s",
GTSL_DispFunc, ShowTime,
PGA_Freedom, LORIENT_HORIZ,
GA_Immediate, TRUE,
GA_RelVerify, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_CLIPPANEL_TEXT_PACING_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTCY_Labels, PacingMode,
GTCY_Active, Config -> ClipConfig -> PacingMode,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_CLIPPANEL_PASTE_PREFIX_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignExtra, TRUE,
GTST_MaxChars, 79,
GTST_String, Config -> ClipConfig -> InsertPrefix,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_CLIPPANEL_PASTE_SUFFIX_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTST_MaxChars, 79,
GTST_String, Config -> ClipConfig -> InsertSuffix,
TAG_DONE);
SZ_ResetMaxWidth();
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_DEFAULT_GAD),0,NULL);
SZ_SetWidth(SZ_ResetMaxWidth());
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_USE_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_AlignExtra, TRUE,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignLeft, TRUE,
SZ_AlignBottom, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_CANCEL_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignRight, TRUE,
TAG_DONE);
if(Default)
{
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_DEFAULT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignCentre, TRUE,
TAG_DONE);
}
}
return(Gadget);
}
BYTE
ClipPanel(struct Configuration *Config,BYTE *Default)
{
struct Window *PanelWindow;
struct Gadget *GadgetList = NULL;
struct Gadget *GadgetArray[GAD_DEFAULT + 1];
SaveConfig(Config,PrivateConfig);
if(CreateAllGadgets(Config,GadgetArray,&GadgetList,Default))
{
if(PanelWindow = OpenWindowTags(NULL,
WA_Left, GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
WA_Top, GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight()) / 2,
WA_Width, SZ_GetWindowWidth(),
WA_Height, SZ_GetWindowHeight(),
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_CustomScreen,Window -> WScreen,
WA_IDCMP, IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | SLIDERIDCMP | BUTTONIDCMP | INTEGERIDCMP | STRINGIDCMP | CYCLEIDCMP,
WA_Title, LocaleString(MSG_CLIPPANEL_CLIP_SETTINGS_TXT),
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG IClass,Code;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
GuideContext(CONTEXT_CLIP);
PushWindow(PanelWindow);
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
ActiveGadget = NULL;
ClrSignal(SIG_BREAK);
while(!Terminated)
{
if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
{
SaveConfig(PrivateConfig,Config);
break;
}
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
IClass = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
KeySelect(GadgetArray,GAD_CANCEL,Code,PanelWindow,&Gadget,&IClass,&Code);
if(IClass == IDCMP_GADGETDOWN)
{
if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
ActiveGadget = Gadget;
}
if(IClass == IDCMP_ACTIVEWINDOW && ActiveGadget)
ActivateGadget(ActiveGadget,PanelWindow,NULL);
if(IClass == IDCMP_CLOSEWINDOW)
{
SaveConfig(PrivateConfig,Config);
Terminated = TRUE;
}
if(IClass == IDCMP_MOUSEMOVE)
{
switch(Gadget -> GadgetID)
{
case GAD_CHARDELAY:
Config -> ClipConfig -> CharDelay = Code;
break;
case GAD_LINEDELAY:
Config -> ClipConfig -> LineDelay = Code;
break;
}
}
if(IClass == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_PACING:
Config -> ClipConfig -> PacingMode = Code;
break;
case GAD_CHARDELAY:
Config -> ClipConfig -> CharDelay = Code;
break;
case GAD_LINEDELAY:
Config -> ClipConfig -> LineDelay = Code;
break;
case GAD_SENDTIMEOUT:
Config -> ClipConfig -> SendTimeout = Code;
break;
case GAD_PREFIX:
ActivateGadget(ActiveGadget = GadgetArray[GAD_SUFFIX],PanelWindow,NULL);
break;
case GAD_USE:
Terminated = TRUE;
strcpy(Config -> ClipConfig -> InsertPrefix, SZ_GetString(GadgetArray[GAD_PREFIX]));
strcpy(Config -> ClipConfig -> InsertSuffix, SZ_GetString(GadgetArray[GAD_SUFFIX]));
strcpy(Config -> ClipConfig -> LinePrompt, SZ_GetString(GadgetArray[GAD_PROMPT]));
Config -> ClipConfig -> ClipboardUnit = SZ_GetInteger(GadgetArray[GAD_UNIT]);
break;
case GAD_CANCEL:
Terminated = TRUE;
SaveConfig(PrivateConfig,Config);
break;
case GAD_DEFAULT:
*Default = TRUE;
Terminated = TRUE;
break;
}
}
}
}
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
}
}
FreeGadgets(GadgetList);
return((BYTE)memcmp(PrivateConfig -> ClipConfig,Config -> ClipConfig,sizeof(struct ClipSettings)));
}